package com.mh.service;

import com.mh.domain.Customer;
import com.mh.domain.Invoice;
import com.mh.domain.Item;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/demo-mh-security-context.xml",
		"file:./resources/demo-mh-service-context.xml",
		"file:./resources/demo-mh-dao-context.xml",
		"file:./resources/demo-mh-web-context.xml" })
@Transactional
public class InvoiceServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected InvoiceService service;

	/**
	 * Instantiates a new InvoiceServiceTest.
	 *
	 */
	public InvoiceServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findInvoiceByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findInvoiceByPrimaryKey 
		Integer id = 0;
		Invoice response = null;
		response = service.findInvoiceByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findInvoiceByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Customer entity
	 * 
	 */
	@Test
	public void deleteInvoiceCustomer() {
		// TODO: JUnit - Populate test inputs for operation: deleteInvoiceCustomer 
		Integer invoice_id = 0;
		Integer related_customer_id = 0;
		Invoice response = null;
		response = service.deleteInvoiceCustomer(invoice_id, related_customer_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInvoiceCustomer
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Invoice entity
	 * 
	 */
	@Test
	public void countInvoices() {
		Integer response = null;
		response = service.countInvoices();
		// TODO: JUnit - Add assertions to test outputs of operation: countInvoices
	}

	/**
	 * Operation Unit Test
	 * Return all Invoice entity
	 * 
	 */
	@Test
	public void findAllInvoices() {
		// TODO: JUnit - Populate test inputs for operation: findAllInvoices 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Invoice> response = null;
		response = service.findAllInvoices(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllInvoices
	}

	/**
	 * Operation Unit Test
	 * Save an existing Customer entity
	 * 
	 */
	@Test
	public void saveInvoiceCustomer() {
		// TODO: JUnit - Populate test inputs for operation: saveInvoiceCustomer 
		Integer id_1 = 0;
		Customer related_customer = new com.mh.domain.Customer();
		Invoice response = null;
		response = service.saveInvoiceCustomer(id_1, related_customer);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInvoiceCustomer
	}

	/**
	 * Operation Unit Test
	 * Load an existing Invoice entity
	 * 
	 */
	@Test
	public void loadInvoices() {
		Set<Invoice> response = null;
		response = service.loadInvoices();
		// TODO: JUnit - Add assertions to test outputs of operation: loadInvoices
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Invoice entity
	 * 
	 */
	@Test
	public void deleteInvoice() {
		// TODO: JUnit - Populate test inputs for operation: deleteInvoice 
		Invoice invoice = new com.mh.domain.Invoice();
		service.deleteInvoice(invoice);
	}

	/**
	 * Operation Unit Test
	 * Save an existing Invoice entity
	 * 
	 */
	@Test
	public void saveInvoice() {
		// TODO: JUnit - Populate test inputs for operation: saveInvoice 
		Invoice invoice_1 = new com.mh.domain.Invoice();
		service.saveInvoice(invoice_1);
	}

	/**
	 * Operation Unit Test
	 * Save an existing Item entity
	 * 
	 */
	@Test
	public void saveInvoiceItems() {
		// TODO: JUnit - Populate test inputs for operation: saveInvoiceItems 
		Integer id_2 = 0;
		Item related_items = new com.mh.domain.Item();
		Invoice response = null;
		response = service.saveInvoiceItems(id_2, related_items);
		// TODO: JUnit - Add assertions to test outputs of operation: saveInvoiceItems
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Item entity
	 * 
	 */
	@Test
	public void deleteInvoiceItems() {
		// TODO: JUnit - Populate test inputs for operation: deleteInvoiceItems 
		Integer invoice_id_1 = 0;
		Integer related_items_id = 0;
		Invoice response = null;
		response = service.deleteInvoiceItems(invoice_id_1, related_items_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteInvoiceItems
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
